package com.zhang.sys;

import com.zhang.BaseHibernateDAO;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * SysSystem entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.zhang.sys.SysSystem
 * @author MyEclipse Persistence Tools
 */

public class SysSystemDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(SysSystemDAO.class);
	// property constants
	public static final String SYS_NAME = "sysName";
	public static final String SYS_LOGO = "sysLogo";
	public static final String SYS_VERSION = "sysVersion";
	public static final String SYS_RIGHT = "sysRight";
	public static final String SYS_LOGIN = "sysLogin";
	public static final String SYS_MAIN1 = "sysMain1";
	public static final String SYS_MAIN2 = "sysMain2";
	public static final String SYS_MAIN3 = "sysMain3";

	public void save(SysSystem transientInstance) {
		log.debug("saving SysSystem instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SysSystem persistentInstance) {
		log.debug("deleting SysSystem instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SysSystem findById(java.lang.String id) {
		log.debug("getting SysSystem instance with id: " + id);
		try {
			SysSystem instance = (SysSystem) getSession().get(
					"com.zhang.sys.SysSystem", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(SysSystem instance) {
		log.debug("finding SysSystem instance by example");
		try {
			List results = getSession().createCriteria(
					"com.zhang.sys.SysSystem").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding SysSystem instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from SysSystem as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findBySysName(Object sysName) {
		return findByProperty(SYS_NAME, sysName);
	}

	public List findBySysLogo(Object sysLogo) {
		return findByProperty(SYS_LOGO, sysLogo);
	}

	public List findBySysVersion(Object sysVersion) {
		return findByProperty(SYS_VERSION, sysVersion);
	}

	public List findBySysRight(Object sysRight) {
		return findByProperty(SYS_RIGHT, sysRight);
	}

	public List findBySysLogin(Object sysLogin) {
		return findByProperty(SYS_LOGIN, sysLogin);
	}

	public List findBySysMain1(Object sysMain1) {
		return findByProperty(SYS_MAIN1, sysMain1);
	}

	public List findBySysMain2(Object sysMain2) {
		return findByProperty(SYS_MAIN2, sysMain2);
	}

	public List findBySysMain3(Object sysMain3) {
		return findByProperty(SYS_MAIN3, sysMain3);
	}

	public List findAll() {
		log.debug("finding all SysSystem instances");
		try {
			String queryString = "from SysSystem";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SysSystem merge(SysSystem detachedInstance) {
		log.debug("merging SysSystem instance");
		try {
			SysSystem result = (SysSystem) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SysSystem instance) {
		log.debug("attaching dirty SysSystem instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SysSystem instance) {
		log.debug("attaching clean SysSystem instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}